====== Research Tools ======

A list of research tools, such as software packages, that I've explored with pros/cons.

====== Stochastic Simulators ======

I'm looking for a stochastic simulation engine.  Here are the features I'd like:
  * easy to use,
  * spatial (and maybe network) support, 
  * fast/efficient, and
  * handles stiff problems accurately.

<sortable>
^ Package                                                                                                                                                        ^ Last Reviewed  ^ Research                                                                                                                            ^ Platform and Requirements       ^ Structure?                                                                                     ^ Pros                        ^ Cons                                                                                                                             ^ Additional Notes                                                                                   ^
| [[http://engineering.ucsb.edu/~cse/StochKit/| StochKit2]]                                                                                                      | 2014-04-11     | [[http://bioinformatics.oxfordjournals.org.ezproxy.library.ubc.ca/content/27/17/2457| Sanft et al., 2011]]                          | Windows or Linux/Unix/Mac OS X  | Well mixed only                                                                                | Supports "slow-scale SSA".  |                                                                                                                                  |                                                                                                    |
| [[http://www.smoldyn.org/| Smoldyn]]                                                                                                                           | 2014-03-14     | [[http://www.ploscompbiol.org/article/info%3Adoi%2F10.1371%2Fjournal.pcbi.1000705| Andrews et al., 2010]]                           | Custom language.                | Spatial                                                                                        | Easy to install/use.        |                                                                                                                                  | Lotka-Volterra demos:\\ * examples\S6_commands\cmdtime1.txt\\ * examples\S8_reactions\lotvolt\...  |
| [[http://nba.uth.tmc.edu/cds/index.htm| Cellular Dynamic Simulator (CDS)]]                                                                                     | 2014-04-04     | [[http://link.springer.com.ezproxy.library.ubc.ca/article/10.1007%2Fs12021-010-9066-x| Byrne et al., 2010]]                         | Java                            | Spatial                                                                                        |                             | Inactive since 2010.                                                                                                             |                                                                                                    |
| [[http://steps.sourceforge.net/STEPS/default.php|  STEPS (STochastic Engine for Pathway Simulation)]]                                                          | 2014-03-28     | [[http://www.biomedcentral.com.ezproxy.library.ubc.ca/1752-0509/6/36/abstract| Hepburn et al., 2012]]                               | Python                          | Spatial                                                                                        |                             | Needs separate 3D modeler to implement spatial structure "meshes".                                                               | Unofficial [[http://www.lfd.uci.edu/~gohlke/pythonlibs/#steps| Windows binaries]] available.       |
| [[http://sourceforge.net/apps/trac/urdme/| URDME]]                                                                                                             | 2014-02-28     | [[http://www.biomedcentral.com.ezproxy.library.ubc.ca/1752-0509/6/76| Drawert et al., 2012]]                                        | MATLAB, GCC                     | Spatial                                                                                        |                             | No Windows support.                                                                                                              |                                                                                                    |
| [[http://www.stochss.org/| StochSS]]                                                                                                                           | 2014-02-21     | [[http://www.sciencedirect.com/science/article/pii/S0021999111001094| Hellander and Lötstedt, 2011]]                                | Python, Amazon EC2              | Well mixed only                                                                                |                             | Windows version doesn't run locally -- only on Amazon cloud.\\ Suggests it uses URDME to do spatial sims but not yet supported.  |                                                                                                    |
| [[http://gfrd.org/| eGFRD (enhanced Green’s Function Reaction Dynamics)]]                                                                                      | 2014-01-31     | [[http://scitation.aip.org.ezproxy.library.ubc.ca/content/aip/journal/jcp/123/23/10.1063/1.2137716| van Zone and ten Wolde, 2005]]  | C++ and (or?) Python            | Continuous space                                                                               |                             | Project seems inactive.\\ Visualization tools appear to be for Linux only.                                                       |                                                                                                    |
| [[http://ccl.northwestern.edu/netlogo/| NetLogo]] with [[http://modelingcommons.org/browse/one_model/3850#model_tabs_browse_discuss| per-capita tau-leaping]]  | 2013-10-08     | none                                                                                                                                | NetLogo                         | Continuous or discrete space, network.\\ Reactions can be nonlocal: eg. A(x) + B(y) --> C(z).  | Easy to install/use.        | Slow.  "per-capita tau leaping" algorithm untested for validity or accuracy.                                                     |                                                                                                    |
</sortable>

====== Agentscript ======

Since Java applets have been deprecated I've been stuck without a way to share models interactively online.  But [[http://agentscript.org/ | Agentscript]] looks very promising.  I've successfully run simple models in all of the following environments:
  * Firefox on Windows
  * Chrome on Windows
  * IE 11
  * Firefox on Android
  * Chrome on Android
  * Safari on iPod

I've started writing a DokuWiki plugin to simplify including Agentscript models on a page: [[https://github.com/rikblok/dokuwiki-plugin-agentscript/archive/master.zip | Download]].

===== Example =====

<agentscript>
    u = ABM.util # ABM.util alias, u.s is also ABM.shape accessor.
    class MyModel extends ABM.Model
      setup: ->
        
        # No optimizations: 10fps
        @patches.usePixels() # 24fps
        # @patches.cacheAgentsHere() # 9-10fps, not needed & modest overhead
        # two: 27fps, now static colors larger percent of faster patches.
        @agents.setUseSprites() # 24->46-48fps!
        
        # @anim.setRate 25, true # normal: let agents step faster than drawing
        @anim.setRate 60, false # speed test
        
        # globals
        @nestColor = [255,255,0]  # yellow
        @foodColor = [0,0,255]    # blue

        # defaults
        @agents.setDefault "shape", "bug"
        @agents.setDefault "color", @foodColor # so default sprite not random color
        @agents.setDefault "size", 3
        
        # UI globals:
        @population = 255
        @maxPheromone = 35
        @diffusionRate = .30
        @evaporationRate = .01
        @wiggleAngle = u.degToRad(30) # radians

        if @agents.useSprites
          # @nestSprite = ABM.shapes.shapeToSprite "bug", @nestColor, 3*@patches.size
          # @foodSprite = ABM.shapes.shapeToSprite "bug", @foodColor, 3*@patches.size
          @nestSprite = ABM.shapes.shapeToSprite "bug", @nestColor, @patches.toBits 3
          @foodSprite = ABM.shapes.shapeToSprite "bug", @foodColor, @patches.toBits 3
        
        @setupPatches()
        @setupAgents()
      step: ->
        console.log @anim.toString() if @anim.ticks % 100 is 0
        @updateAgents()
        @updatePatches()

      setupPatches: ->
        for p in @patches
          p.isNest = false ; p.isFood = false 
          # REMIND: agentsOwn etc; NL defaults to 0
          p.foodPheromone = 0; p.nestPheromone = 0
        (p.isNest=true;p.color=@nestColor) for p in @patchRect @patches.maxX-6,0,3,3
        (p.isFood=true;p.color=@foodColor) for p in @patchRect @patches.minX+6,0,3,3
        null
      setupAgents: -> # a is agent
        @agents.create @population, (a) => # fat arrow for @patches etc
          #a.shape = "bug"
          #a.size = 3
          a.setXY @patches.maxX-6, 0
          @resetAgent(a, false) # sets a.pheromone to max
      resetAgent: (a, withFood) ->
        a.carryingFood = withFood
        if @agents.useSprites
          a.sprite = if withFood then @nestSprite else @foodSprite
          # a.setSprite (if withFood then @nestSprite else @foodSprite)
        else
          a.color = if withFood then @nestColor else @foodColor
          # a.colorStr = u.colorStr a.color if @agents.staticColors
        a.pheromone = @maxPheromone

      updateAgents: ->
        for a in @agents when a.id < @anim.ticks # gradually leave nest
            @wiggleUphill a
            @dropPheromone a
        null # needed to avoid returning an absurd comprehension
      wiggleUphill: (a) ->
        if a.p.isOnEdge()
          # a.rotate Math.PI 
          a.rotate u.degToRad(180)
        else
          # nAhead = a.inCone a.p.n, Math.PI, 2
          nAhead = a.inCone a.p.n, u.degToRad(180), 2
          # nAhead = a.p.n.inCone a.p, a.heading, u.degToRad(180), 2
          # nAhead = ABM.patches.inCone a.p, a.heading, u.degToRad(180), 2
          [p, max] = nAhead.maxOneOf ((n) => @targetPheromone(a, n)), true # => for @
          a.face p if max > .001/@maxPheromone
          # p = nAhead.maxOneOf ((n) => @targetPheromone(a, n)) # => for @
          # max = @targetPheromone(a, p)
          # a.face p if max > .001/@maxPheromone
        a.rotate u.randomCentered(@wiggleAngle)
        a.forward 1
      targetPheromone: (a, p) -> 
        if a.carryingFood then p.nestPheromone else p.foodPheromone
      dropPheromone: (a) ->
        if (not a.carryingFood and a.p.isFood) or (a.carryingFood and a.p.isNest)
          @resetAgent a, not a.carryingFood
        if a.carryingFood
        then a.p.foodPheromone += 0.1*a.pheromone
        else a.p.nestPheromone += 0.1*a.pheromone
        a.pheromone *= 0.9
      
      updatePatches: ->
        @patches.diffuse "nestPheromone", @diffusionRate
        @patches.diffuse "foodPheromone", @diffusionRate
        for p in @patches
          p.foodPheromone *= (1 - @evaporationRate)
          p.nestPheromone *= (1 - @evaporationRate)
          p.foodPheromone = p.nestPheromone = 0 if p.isOnEdge()
          unless (p.isNest or p.isFood) #  or p.isOnEdge()
            if p.foodPheromone > p.nestPheromone
            then p.scaleColor @foodColor, p.foodPheromone
            else p.scaleColor @nestColor, p.nestPheromone
        null

      # utilities
      patchRect: (x, y, dw, dh) ->
        @patches.patchRect @patches.patch(x,y), dw, dh, true

    # div, patchSize, minX, maxX, minY, maxY, isTorus, hasNeighbors
    #   Defaults: 13, -16, 16, -16, 16, false, true
    model = new MyModel {
      div: "layers",
      size: 6,
      minX: -40,
      maxX: 40,
      minY: -40,
      maxY: 40
    }
    model.debug() # Debug: Put Model vars in global name space
    model.start() # Run model immediately after startup initialization
</agentscript>

===== To do =====

There are many things left to do:
  - User-configurable CDNs for Coffeescript and Agentscript.
  - Allow [[http://agentscript.org/sketches/jsmodel.html | Javascript models]] instead of Coffeescript?
  - Provide setup and step (forever) buttons.  See [[http://bl.ocks.org/stepheneb/raw/4705258/07dfc353034ab35b4fcbd7387ac1774090068c6e/| here]] for UI ideas.
  - Allow source file in media folder instead of inline code?
  - How to handle optional Agentscript [[http://agentscript.org/ |add-ons]]?
  - Build test models, eg. [[:science:popmod:conway_s_game_of_life:start]]
  - How to secure against running arbitrary code?
  - Add a noscript warning to tell the user they're missing out :)